import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.irdstudio.biz.drools.beans.RuleBean;
import com.irdstudio.biz.drools.beans.RuleResultBean;
import com.irdstudio.biz.drools.common.MapHelper;
import com.irdstudio.biz.rule.common.BizUtil;
import com.irdstudio.biz.rule.common.constant.Constant;
import com.irdstudio.biz.rule.common.constant.Constant.RULE_COLL_STATE;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

public class MapHelperTestUnit extends TestCase {

    Logger log = LoggerFactory.getLogger(this.getClass());

    Map<String, Object> input;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        before();
    }

    public void before() throws IOException {
        InputStream jsonInput = this.getClass().getResourceAsStream("helper.json");
        Assert.assertNotNull(jsonInput);
        String json = IOUtils.toString(jsonInput, "UTF-8");
        input = JSON.parseObject(json, Map.class);
        Assert.assertNotNull(input);
    }

    public void test() {

        log.info( "" + MapHelper.getValue(input, "input"));
        log.info( MapHelper.getProperty(input, "input.case_info.ltv", String.class));
        log.info( MapHelper.getProperty(input, "input.case_mort.case_mort_ext.decoration", String.class));
        log.info( MapHelper.getMapList(input, "input.case_mort.case_cprt") + "");
        log.info( MapHelper.getValue(input, "input.case_mort.case_cprt.cprt_trade") + "");

        String uuid = BizUtil.getUUID("L");
        log.info(uuid);
        log.info(DigestUtils.md5Hex(uuid));

    }

    public void testJSON() {
        RuleBean ruleBean = new RuleBean();
        System.out.println(JSON.toJSONString(ruleBean, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullListAsEmpty));
    }

    public void testEnum() {
        System.out.println(Enum.valueOf(RuleBean.RESULT.class, "ACCEPT"));
        System.out.println(Constant.get(RULE_COLL_STATE.class, "0"));
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
        System.out.println("after ***************");
    }
}
